<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
            Promise.all,可以一次发送所有的请求，请求都回来之后，才进入回调
            可以避免每一个请求都在等待的问题
            语法： Promise.all([promise1,promise2,promiseN]).then()
        */
      function fn1() {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            console.log("fn1，1秒完成");
            resolve();
          }, 1000);
        });
      }
      function fn2() {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            console.log("fn2，2秒完成");
            resolve();
          }, 2000);
        });
      }
      function fn3() {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            console.log("fn3，3秒完成");
            resolve();
          }, 3000);
        });
      }

      console.time();
      //   记得要调用 fn1()
      Promise.all([fn1(), fn2(), fn3()]).then(() => {
        console.log("所有请求都完成了");
        console.timeEnd();
      });
    </script>
  </body>
</html>
